package com.it.controller;

import com.it.pojo.Menu;
import com.it.pojo.Role;
import com.it.pojo.vo.UserVo;
import com.it.service.MenuService;
import com.it.service.RoleService;
import com.it.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author: zgc
 * @version: 1.0
 * @description:
 * @date: 2023/12/18 17:02
 */

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/findById/{id}")
    @ResponseBody
    public Role findById(@PathVariable("id") String roleId){
        Role role = roleService.findById(roleId);
        return role;
    }
    /*角色授权*/
    @GetMapping("/list")
    public ModelAndView list(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pages/user/roleList");
        /*查询所有角色*/
        List<Role> roleList = roleService.findAll();
        modelAndView.addObject("roleList",roleList);
        return modelAndView;
    }

    /*删除角色  假删除*/
    @GetMapping("/delRoleId/{roleId}")
    public String delRoleId(@PathVariable("roleId") String roleId){
        roleService.deleteByRolId(roleId);
        return "redirect:/role/list";
    }

    /*根据roleId查询角色信息*/
    /*@GetMapping("/findByRoleId/{roleId}")
    public ModelAndView findByRoleId(@PathVariable("roleId") String roleId){
        System.out.println(roleId);
        ModelAndView modelAndView = new ModelAndView();
        Role role = roleService.findById(roleId);
        System.out.println(role);
        modelAndView.addObject("r",role);
        return modelAndView;
    }*/

    @PostMapping("/updateRoleId")
    public String updateRoleId(Role role){
        roleService.updateRole(role);
        return "redirect:/role/list";
    }







}
